﻿namespace SAD.ShowNodeClientLib
{
    using System;
    using SAD.ClientLogic;

    public class InfoReceiverManager
    {
        public DateTime LastInfoTime
        {
            get { return m_LastInfoTime; }
        }
        private DateTime m_LastInfoTime;

        #region Instance
        /// <summary>
        /// 类型单例
        /// </summary>
        public static InfoReceiverManager Instance
        {
            get
            {
                return m_Instance;
            }
        }
        private static InfoReceiverManager m_Instance = new InfoReceiverManager();
        #endregion

        private InfoReceiverManager()
        {
            PushInfoReceiver.Instance.Init(this);

            re = new PullInfoReceiver();
            re.Init(this);
            
        }

        public void Start()
        {
            re.Start();
        }
        PullInfoReceiver re;

        public delegate void AddInfoHandler(SAD.Common.Models.Info_Data info);
        public event AddInfoHandler AddInfoEvent;

        public delegate void RemoveInfoHandler(long infoID, int categoryID);
        public event RemoveInfoHandler RemoveInfoEvent;

        public void OnAddInfoEvent(SAD.Common.Models.Info_Data info)
        {
            if (AddInfoEvent != null)
            {
                AddInfoEvent(info);
            }

            this.UpdateLastInfoTime(info.AddTime);
        }

        public void OnRemoveInfoEvent(long infoID, int categoryID)
        {
            if (RemoveInfoEvent != null)
            {
                RemoveInfoEvent(infoID, categoryID);
            }
        }

        public void UpdateLastInfoTime(DateTime time)
        {
            if (time > m_LastInfoTime)
            {
                m_LastInfoTime = time;
            }
        }
    }
}